package com.hongxin.nw.netty.model.packing.info;

import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.values.TypeIdentif;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

/**
 * @remark A.6 黑名单下发时下行数据
 * @author: GuoXiaolin
 * @date 2019/5/28 10:05
 * @Version 1.0
 * @Descibe
 */
@Slf4j
@Getter
@Setter
public class Csdna1_1 implements IPacking {

    private String co;//1	充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String chargeIdentify;//2	充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String timeNum;//3	时间戳序号	压缩BCD码	9Byte	省编号+YYYYMMDDhhmmss+序号，例如：312013051412010159
    private String blackNum;//4	黑名单数量	BIN码	1Byte	黑名单数不多于255

    //5	物理卡号	压缩BCD码	8Byte	16位编码
    //6	状态	压缩BCD码	1Byte	1-挂失 2-解挂
    //…	….	…	…	…
    //N+6	物理卡号	压缩BCD码	8Byte	16位编码,第N个黑名单
    //N+7	状态	压缩BCD码	1Byte	1-挂失 2-解挂，第N个黑名单状态
    private StringBuilder physicsNums = new StringBuilder();

    public Csdna1_1 setCo(String co) {
        this.co = FieldPack.caseToBCD(co, TypeIdentif.BYTE_CO.getByteLength());
        return this;
    }

    public Csdna1_1 setChargeIdentify(String chargeIdentify) {
        this.chargeIdentify = FieldPack.caseToBin(chargeIdentify, TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_1 setTimeNum(String timeNum) {
        this.timeNum =  FieldPack.caseToBCD(timeNum, TypeIdentif.BYTE_CARD.getByteLength());
        return this;
    }
    public Csdna1_1 setBlackNum(String blackNum) {
        this.blackNum =  FieldPack.caseToBin(blackNum, TypeIdentif.BYTE_CAR_IDENTIFY_32.getByteLength());
        return this;
    }
    public Csdna1_1 setPhysicsNums(List<Map<String ,Object>> list) {
        for (Map<String, Object> map : list) {
            String physicsNum = FieldPack.caseToBCD(String.valueOf(map.get("physicsNum")), TypeIdentif.BYTE_PHYSICS_NUM.getByteLength());
            String status = FieldPack.caseToBCD(String.valueOf(map.get("status")), TypeIdentif.BYTE_REPORT_STATUS.getByteLength());
            this.physicsNums.append(physicsNum).append(status);
        }
        return this;

//        for (int i = 0; i < list.size(); i++){
//            Map<String ,Object> map = list.get(i);
//            String physicsNum = FieldPack.caseToBCD(String.valueOf(map.get("physicsNum")), TypeIdentif.BYTE_PHYSICS_NUM.getByteLength());
//            String status = FieldPack.caseToBCD(String.valueOf(map.get("status")), TypeIdentif.BYTE_REPORT_STATUS.getByteLength());
//            this.physicsNums.append(physicsNum).append(status);
//        }
//        return this;
    }

    @Override
    public String packing() {
        return this.co +
                this.chargeIdentify +
                this.timeNum +
                this.blackNum +
                this.physicsNums.toString();
    }

    @Override
    public String toString() {
        return "Csdna1_1{" +
                "co='" + co + '\'' +
                ", chargeIdentify='" + chargeIdentify + '\'' +
                ", timeNum='" + timeNum + '\'' +
                ", blackNum='" + blackNum + '\'' +
                ", physicsNums=" + physicsNums +
                '}';
    }
}
